﻿if (typeof ($) != "undefined") {
    $(document).ready(function () {
        var now = new Date();
        y = now.getFullYear();
        m = now.getMonth() + 1;
        d = now.getDate();
        m = m < 10 ? "0" + m : m;
        d = d < 10 ? "0" + d : d;
        var myDate = y + "-" + m + "-" + d;
        var fun = getPar1("fun");
        if (fun == "add") { //新增
            instance[0].Status = "1"; //状态为未审批
            instance[0].RegisterDate = myDate; //登记日期
            //获取拟定人employeeId
            YAHOO.util.Connect.asyncRequest('POST', "../EHR/GetCurrentUser.aspx", {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str != "-1") {
                            var token = str.split('_');
                            $("#makeMan").val(token[1]); //拟定人
                            $("#makeDate").val(myDate); //拟定日期
                            instance[0].ApplyMan = token[0];
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }
        else if (fun == "edit") { //修改
            instance[0].Status = "1"; //状态为未审批
            var applyMan = getPar(decodeURI(location.href), "applyMan");
            var applyDate = getPar(decodeURI(location.href), "applyDate");
            $("#makeMan").val(applyMan); //拟定人
            $("#makeDate").val(applyDate); //拟定日期
        }
        else if (fun == "view") //查看
        {
            var applyMan = getPar(decodeURI(location.href), "applyMan");
            var applyDate = getPar(decodeURI(location.href), "applyDate");
            $("#makeMan").val(applyMan); //拟定人
            $("#makeDate").val(applyDate); //拟定日期
            //设置只可读，并且背景色为烟灰色
            $("#PlanName").attr("readonly", "readonly");
            $("#PlanName").css("background", "whitesmoke");
            $("#RecruitmentSource").attr("disabled", true);
            $("#RecruitmentSource").css("background", "whitesmoke");
            $("#BudgetFee").attr("readonly", "readonly");
            $("#BudgetFee").css("background", "whitesmoke");
            $("#BeginDate").attr("disabled", true);
            $("#BeginDate").css("background", "whitesmoke");
            $("#EndDate").attr("disabled", true);
            $("#EndDate").css("background", "whitesmoke");
            $("#Remark").attr("readonly", "readonly");
            $("#Remark").css("background", "whitesmoke");
            var btn = parent.document.getElementById("yui-gen7-button");
            $(btn).hide();
        }
        else if (fun == "audit") { //审批
            //获取审批人employeeId
            YAHOO.util.Connect.asyncRequest('POST', "../EHR/GetCurrentUser.aspx", {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str != "-1") {
                            var token = str.split('_');
                            $("#table").append("<tr><td class='td_text'>审批人：</td><td class='td_value'><input  id='auditPerson' name='auditPerson' type='text' readonly='readonly' style='background-color: whitesmoke; width: 152px'/><span style='color: #ff0000'>*</span></td><td class='td_text'>审批日期：</td><td class='td_value'><input class='Wdate' datafields='AuditDate' id='AuditDate' name='AuditDate'  onclick='WdatePicker()' readonly='readonly' style='background-color: whitesmoke; width: 152px' type='text' /><span style='color: #ff0000'>*</span></td></tr><tr><td class='td_text'>审批结果：</td><td class='td_value'><select id='auditResult' name='AuditRemark' style='width: 156px' title=''></select><span style='color: #ff0000'>*</span></td><td class='td_text'>&nbsp;</td><td class='td_value'>&nbsp;</td></tr><tr><td class='td_text'>审批说明：</td><td class='td_value' colspan='3'><textarea cols='30' datafields='AuditRemark' id='AuditRemark' name='AuditRemark' rows='4'></textarea></td></tr>");
                            var applyMan = getPar(decodeURI(location.href), "applyMan");
                            var applyDate = getPar(decodeURI(location.href), "applyDate");
                            $("#makeMan").val(applyMan); //拟定人
                            $("#makeDate").val(applyDate); //拟定日期
                            $("#auditPerson").val(token[1]); //审批人
                            $("#AuditDate").val(myDate); //审批日期
                            instance[0].AuditMan = token[0];
                            $("#auditResult").append("<option value='2'>通过</option>");
                            $("#auditResult").append("<option value='3'>不通过</option>");
                            $("#Status").val("2");
                            $("#auditResult").change(function () {
                                $("#Status").val($("#auditResult").val());
                            });
                            //设置只可读，并且背景色为烟灰色
                            $("#PlanName").attr("readonly", "readonly");
                            $("#PlanName").css("background", "whitesmoke");
                            $("#RecruitmentSource").attr("disabled", true);
                            $("#RecruitmentSource").css("background", "whitesmoke");
                            $("#BudgetFee").attr("readonly", "readonly");
                            $("#BudgetFee").css("background", "whitesmoke");
                            $("#BeginDate").attr("disabled", true);
                            $("#BeginDate").css("background", "whitesmoke");
                            $("#EndDate").attr("disabled", true);
                            $("#EndDate").css("background", "whitesmoke");
                            $("#Remark").attr("readonly", "readonly");
                            $("#Remark").css("background", "whitesmoke");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }
    });
}

//数据验证
var fnCheckData = function () {
    if ($("#PlanName").val() == "") {
        return "招聘计划名称不能为空！";
    }
    //验证日期
    var now = new Date();
    y = now.getFullYear();
    m = now.getMonth() + 1;
    d = now.getDate();
    m = m < 10 ? "0" + m : m;
    d = d < 10 ? "0" + d : d;
    var begin = y + "-" + m + "-" + d;
    var date1 = $("#BeginDate").val();
    if (date1 == "") {
        return "开始日期不能为空！";
    }
    var date2 = $("#EndDate").val();
    if (date2 == "") {
        return "结束日期不能为空！";
    } var id = getPar1("id");
    if (typeof (id) == "undefined") { //新增
        if (begin >= date1) {
            return "开始日期小于当前日期，不允许!";
        }
        if (begin >= date2) {
            return "结束日期小于当前日期，不允许!";
        }
    }
    if (date1 > date2) {
        return "开始日期小于结束日期，不允许!";
    }
}